// Verilated -*- C++ -*-
// DESCRIPTION: Verilator output: Design implementation internals
// See VkeyFilter.h for the primary calling header

#include "verilated.h"

#include "VkeyFilter___024root.h"

VL_INLINE_OPT void VkeyFilter___024root___sequent__TOP__1(VkeyFilter___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    VkeyFilter__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    VkeyFilter___024root___sequent__TOP__1\n"); );
    // Body
    if (vlSelf->rstn) {
        vlSelf->okey = ((1U != (IData)(vlSelf->keyFilter__DOT__nstate)) 
                        & ((2U == (IData)(vlSelf->keyFilter__DOT__nstate))
                            ? (IData)(vlSelf->okey)
                            : ((4U == (IData)(vlSelf->keyFilter__DOT__nstate)) 
                               | (IData)(vlSelf->okey))));
        vlSelf->keyFilter__DOT__cnt = ((2U == (IData)(vlSelf->keyFilter__DOT__cstate))
                                        ? (0x3ffffffU 
                                           & ((IData)(1U) 
                                              + vlSelf->keyFilter__DOT__cnt))
                                        : 0U);
    } else {
        vlSelf->okey = 0U;
        vlSelf->keyFilter__DOT__cnt = 0U;
    }
    vlSelf->keyFilter__DOT__key_in_r = (1U & ((~ (IData)(vlSelf->rstn)) 
                                              | (IData)(vlSelf->ikey)));
    vlSelf->keyFilter__DOT__cstate = ((IData)(vlSelf->rstn)
                                       ? (IData)(vlSelf->keyFilter__DOT__nstate)
                                       : 1U);
}

VL_INLINE_OPT void VkeyFilter___024root___settle__TOP__2(VkeyFilter___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    VkeyFilter__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    VkeyFilter___024root___settle__TOP__2\n"); );
    // Body
    vlSelf->keyFilter__DOT__key_pos = ((IData)(vlSelf->ikey) 
                                       & (~ (IData)(vlSelf->keyFilter__DOT__key_in_r)));
    vlSelf->keyFilter__DOT__key_neg = ((~ (IData)(vlSelf->ikey)) 
                                       & (IData)(vlSelf->keyFilter__DOT__key_in_r));
    vlSelf->keyFilter__DOT__nstate = vlSelf->keyFilter__DOT__cstate;
    if ((1U == (IData)(vlSelf->keyFilter__DOT__cstate))) {
        if (vlSelf->keyFilter__DOT__key_neg) {
            vlSelf->keyFilter__DOT__nstate = 2U;
        }
    } else if ((2U == (IData)(vlSelf->keyFilter__DOT__cstate))) {
        if (((~ (IData)(vlSelf->okey)) & (IData)(vlSelf->keyFilter__DOT__key_pos))) {
            vlSelf->keyFilter__DOT__nstate = 1U;
        } else if (((IData)(vlSelf->okey) & (IData)(vlSelf->keyFilter__DOT__key_neg))) {
            vlSelf->keyFilter__DOT__nstate = 4U;
        } else if (((0x31U == vlSelf->keyFilter__DOT__cnt) 
                    & (~ (IData)(vlSelf->okey)))) {
            vlSelf->keyFilter__DOT__nstate = 4U;
        } else if (((0x31U == vlSelf->keyFilter__DOT__cnt) 
                    & (IData)(vlSelf->okey))) {
            vlSelf->keyFilter__DOT__nstate = 1U;
        }
    } else if ((4U == (IData)(vlSelf->keyFilter__DOT__cstate))) {
        if (vlSelf->keyFilter__DOT__key_pos) {
            vlSelf->keyFilter__DOT__nstate = 2U;
        }
    } else {
        vlSelf->keyFilter__DOT__nstate = vlSelf->keyFilter__DOT__cstate;
    }
}

void VkeyFilter___024root___eval(VkeyFilter___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    VkeyFilter__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    VkeyFilter___024root___eval\n"); );
    // Body
    if ((((IData)(vlSelf->clk) & (~ (IData)(vlSelf->__Vclklast__TOP__clk))) 
         | ((~ (IData)(vlSelf->rstn)) & (IData)(vlSelf->__Vclklast__TOP__rstn)))) {
        VkeyFilter___024root___sequent__TOP__1(vlSelf);
        vlSelf->__Vm_traceActivity[1U] = 1U;
    }
    VkeyFilter___024root___settle__TOP__2(vlSelf);
    vlSelf->__Vm_traceActivity[2U] = 1U;
    // Final
    vlSelf->__Vclklast__TOP__clk = vlSelf->clk;
    vlSelf->__Vclklast__TOP__rstn = vlSelf->rstn;
}

#ifdef VL_DEBUG
void VkeyFilter___024root___eval_debug_assertions(VkeyFilter___024root* vlSelf) {
    if (false && vlSelf) {}  // Prevent unused
    VkeyFilter__Syms* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;
    VL_DEBUG_IF(VL_DBG_MSGF("+    VkeyFilter___024root___eval_debug_assertions\n"); );
    // Body
    if (VL_UNLIKELY((vlSelf->clk & 0xfeU))) {
        Verilated::overWidthError("clk");}
    if (VL_UNLIKELY((vlSelf->rstn & 0xfeU))) {
        Verilated::overWidthError("rstn");}
    if (VL_UNLIKELY((vlSelf->ikey & 0xfeU))) {
        Verilated::overWidthError("ikey");}
}
#endif  // VL_DEBUG
